<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$USER = getAccountUserObject();
	if(isset($_SESSION['agent_escort_id'])){
		$ESCORT = $this->escort_entity->init('user_id',$USER->getId());
		
		$subscriptionArray = array(); 
		$subsJsonArray = array();
		foreach(getSubcriptionData_ioc() as $key=>$arrayValue){
			$subscriptionArray[$key] =  $arrayValue[0].' '.$arrayValue[1].' &euro;';
			$subsJsonArray[$key] = $arrayValue[1];
		}
		 
		$listPlaceArray = array();
		$placeJsonArray = array();
		foreach(getPlaceListWorkData_ioc() as $key=>$arrayValue){
			$listPlaceArray[$key] = $arrayValue[0].' '.$arrayValue[1].' &euro;';
			$placeJsonArray[$key] = $arrayValue[1];
		}
		
		$listPackArray = array();
		$packJsonArray = array();
		foreach(getPackListData_ioc() as $key=>$arrayValue){
			$listPackArray[$key] = $arrayValue[0].' '.$arrayValue[1].' &euro;';
			$packJsonArray[$key] = $arrayValue[1];
		}
		
		$listPriorityArray = array();
		$priorityJsonArray = array();
		foreach(getPriorityData_ioc() as $key=>$arrayValue){
			$listPriorityArray[$key] = $arrayValue[0].' '.$arrayValue[1].' &euro;';
			$priorityJsonArray[$key] = $arrayValue[1];
		}
	}
?>
<style>
	
</style>

<script type="text/javascript">
	var subs = JSON.parse('<?php echo json_encode($subsJsonArray);?>');
	var place = JSON.parse('<?php echo json_encode($placeJsonArray);?>');
	var pack = JSON.parse('<?php echo json_encode($packJsonArray);?>');
	var priority = JSON.parse('<?php echo json_encode($priorityJsonArray);?>');
	var EURO_MONTHLY = ' <?php echo language_translate('services_page_euro_monthly');?>';
	function returnValueJSON(json,key){
		return parseFloat( json[key] );
	}
</script>

<form action="<?php echo site_url('agent/transaction_submit/submit_services_nextmonth');?>" name="submit_services_nextmonth" id="submit_services_nextmonth" method="post" enctype="multipart/form-data" >

	<div id="content-left">
		<div id="personal-tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
				<!-- content -->	
				<?php if(isset($ESCORT)): ?>
					<div class="dashboard-info-wrapper">
						<div class="dashboard-info-left"><span><?php echo language_translate('services_page_current');?></span></div>
						<div class="dashboard-info-right">
							<div class="select-box">
								<span style="float:left;"><?php echo loader_image_s('id="id_loader_pic" class="hidden"');?></span>
								<span id="current_price" style="float:left;"> </span> 
							</div>
						</div>
						<div class="clear"></div>
					</div>
					
					<div class="dashboard-info-wrapper">
						<div class="dashboard-info-left"><span><?php echo language_translate('services_page_subscription');?></span></div>
						<div class="dashboard-info-right">
							<div class="select-box">
								<?php echo form_dropdown('subscription', $subscriptionArray, array() , 'id="subscription" class="normal"' );?>
							</div>
						 </div>
						<div class="clear"></div>
					</div>	
			
					<div class="dashboard-info-wrapper">
						<div class="dashboard-info-left"><span><?php echo language_translate('services_page_where_do_you_work');?></span></div>
						<div class="dashboard-info-right">
							<div class="select-box">
								<table>
									<thead>
										<th><?php echo language_translate('services_page_table_head_country');?></th>
										<th><?php echo language_translate('services_page_table_head_state');?></th>
										<th><?php echo language_translate('services_page_table_head_province');?></th>
										<th><?php echo language_translate('services_page_table_head_city');?></th>
										<th><?php echo language_translate('services_page_table_head_price');?></th>
										<th><?php echo language_translate('services_page_table_head_action');?></th>
									</thead>
									<tbody>
										<?php
											foreach($listPlaceArray as $k =>$v):
											$placeInfo = getPlaceListDataInfoById($k);
											//echo multi_checkbox('list_place[]',$listPlaceArray,explode(',', $ESCORT->getPlacesListIdsContract()));					
										?>
											<?php if($placeInfo):?>
											<tr>
												<td>
													<?php echo $placeInfo['country'];?>
												</td>
												<td>
													<?php echo $placeInfo['state'];?>
												</td>
												<td>
													<?php echo $placeInfo['province'];?>
												</td>
												<td>
													<?php echo $placeInfo['city'];?>
												</td>
												<td>
													<?php echo $placeInfo['price'].' &euro;';?>
												</td>
												<td>
													<?php 
														$checked = '';
													?>
													<input type="checkbox" name="list_place[]" value="<?php echo $placeInfo['id'];?>" <?php echo $checked;?> class="custom" />
												</td>
											</tr>
											<?php endif;?>
										<?php endforeach; ?>
									</tbody>
								</table>
							</div>
						 </div>
						<div class="clear"></div>
					</div>
					
					<div class="dashboard-info-wrapper">
						<div class="dashboard-info-left"><span><?php echo language_translate('services_page_add_a_pack');?></span></div>
						<div class="dashboard-info-right">
							<div class="select-box">
								<?php
									echo multi_checkbox('list_pack[]',$listPackArray,array());				
								?>
							</div>
						 </div>
						<div class="clear"></div>
					</div>
					
					<div class="dashboard-info-wrapper">
						<div class="dashboard-info-left"><span><?php echo language_translate('services_page_priority');?></span></div>
						<div class="dashboard-info-right">
							<div class="select-box">
								<?php
									echo multi_checkbox('list_priority[]',$listPriorityArray,array());				
								?>
							</div>
						 </div>
						<div class="clear"></div>
					</div>
					
					<div class="dashboard-info-wrapper">
						<div class="dashboard-info-left"><span>&nbsp;</span></div>
						<div class="dashboard-info-right">
							<div class="select-box">
								<input type="submit" class="save-button" value="<?php echo language_translate('services_page_contract');?>" /> 
								<?php echo loader_image("id='loader_image' class='hidden'");?>
							</div>
						 </div>
						<div class="clear"></div>
					</div>	 
					
					<div class="dashboard-info-wrapper">
						<div id="update-message"><?php echo language_translate('update_successfully_message');?></div>
						<div class="clear"></div>
					</div>
				<?php endif;?>
				<!-- end content -->
			</div>
		</div>
	</div>

</form>

<?php $this->load->view('agent/right_nav'); ?>



<script type="text/javascript">
	$(document).ready(function() { 
		
	});	

	$(document).ready(function() {
		var options = { 
			beforeSubmit:  validateB4Submit,  
			success:       processAfterResponding   
		};	
		$('#submit_services_nextmonth').ajaxForm(options); 
		
		$('#subscription').live('change',function(){	 
			updatePriceJS();
		});
		$('.jquery-safari-checkbox').bind('click',function(){updatePriceJS();});
		updatePriceJS();
	});	
	
	function updatePriceJS(){
		$subscription_id = $('#subscription').val();
		$list_place = getMultiCheckbox('list_place');
		$list_pack = getMultiCheckbox('list_pack');
		$list_priority = getMultiCheckbox('list_priority');
		
		var price = 0;
		price += returnValueJSON(subs,$subscription_id);
		
		for(var i=0; i<$list_place.length; i++){
			price += returnValueJSON(place,$list_place[i]);
		}
		for(var i=0; i<$list_pack.length; i++){
			price += returnValueJSON(pack,$list_pack[i]);
		}
		for(var i=0; i<$list_priority.length; i++){
			price += returnValueJSON(priority,$list_priority[i]);
		}
		
		$('#current_price').html(price + EURO_MONTHLY);
	}

	function validateB4Submit(formData, jqForm, options){
		$('#loader_image').show();
		return true;
	}

	function processAfterResponding(responseText, statusText, xhr, $form) {
		$('#loader_image').hide();	
		if(responseText == 'ok'){
			updatedShow();
		}else{
			debug(responseText);
		}
	}
	
	
</script>